// pages/buyed/buyed.js
const db = wx.cloud.database();
var util = require('../../util/util.js');

Page({
  data: {
    carts: {},
    dis:false
  },
  onLoad: function () {
    var openId = wx.getStorageSync('openId');
    const _ = db.command
    let p1 = new Promise((resolve, reject) => {
      db.collection('dsbsaled').orderBy('buytime','desc').where({
        /*按买的时间降序排列*/
        _openid: openId
      }).get().then(res => {
        var all = res.data;
        resolve(all);
      })
    })
    Promise.all([p1]).then((result) => {
      let all = result[0];
      let allstr = all[0].allStr;
      for (var index in all) {
        all[index].time = util.formatTime(all[index].buytime);
       // all[index].allStr = this.toHide(all[index].allStr);
      };
      this.setData({
        carts: all
      })
    })
  },

  jz:function(){
    var carts = this.data.carts;
    console.log(carts);
    var openId = wx.getStorageSync('openId');
    const _ = db.command
    let p1 = new Promise((resolve, reject) => {
      db.collection('dsbsaled').orderBy('buytime','desc').where({
        /*按买的时间降序排列*/
        _openid: openId
      }).skip(20).get().then(res => {
        var all = res.data;
        resolve(all);
      })
    })
    Promise.all([p1]).then((result) => {
      let all = result[0];
      for (var index in all) {
        all[index].time = util.formatTime(all[index].buytime)
      };
      var a = [];
      a = carts.concat(all);
      this.setData({
        carts: a,
        dis:true
      })
    })
  }
})